<?php
class DataOperation
{

    public static function request($key =   NULL)/*{{{*/
    {
        if (!isset($_REQUEST[$key]) &&  empty($key))
        {
            $result     =   $_REQUEST;
        }
        else
        {
            if (isset($_REQUEST[$key]))
                $result =   $_REQUEST[$key];
            else
                $result =   NULL;
        }

        return  $result;
    }/*}}}*/
    public static function get($key =   NULL)/*{{{*/
    {
        return  self::request($key);
        if (!isset($_GET[$key]) &&  empty($key))
        {
            $result     =   $_GET;
        }
        else
        {
            if (isset($_GET[$key]))
                $result =   $_GET[$key];
            else
                $result =   NULL;
        }
        return  $result;
    }/*}}}*/
    public static function post($key =  NULL)/*{{{*/
    {
        return  self::request($key);
        if (!isset($_POST[$key]) &&  empty($key))
        {
            $result     =   $_POST;
        }
        else
        {
            if (isset($_POST[$key]))
                $result =   $_POST[$key];
            else
                $result =   $_POST[$key];
        }
        return  $result;
    }/*}}}*/

    public static function getCookie($key = NULL)/*{{{*/
    {
        if (is_null($key))  return  $_COOKIE;

        if (isset($_COOKIE[$key]))  return  $_COOKIE[$key];

        return  NULL;
    }/*}}}*/
    public static function setCookie($key, $value , $expire = 0)/*{{{*/
    {
        if (is_null($key))  return  FALSE;

        setCookie($key , $value , $expire);

        return  TRUE;
    }/*}}}*/

    public static function startSession()/*{{{*/
    {
        session_start();
    }/*}}}*/
    public static function getSession($key = NULL)/*{{{*/
    {
        if (is_null($key))  return  $_SESSION;

        if (isset($_SESSION[$key])) return  $_SESSION[$key];

        return  NULL;
    }/*}}}*/
    public static function setSession($key, $value)/*{{{*/
    {
        if (is_null($key))  
        {
            $_SESSION   =   NULL;
            session_destroy();
        }
        else
        {
            $_SESSION[$key] =   $value;
        }

        return  TRUE;
    }/*}}}*/

    public static function encodeData($array)/*{{{*/
    {
        return  json_encode($array);
    }/*}}}*/
    public static function decodeData($string)/*{{{*/
    {
        return  json_decode($string, TRUE);
    }/*}}}*/

    public static function callRemoteServer($url)/*{{{*/
    {
        if (empty($url))    return  NULL;
        $result =   file_get_contents($url);
        return  $result;
    }/*}}}*/

    public static function replaceData($string, $source = "'", $target = '"')/*{{{*/
    {
        $result =   str_replace($source, $target, $string);

        $length =   strlen($result);
        if (!empty($length) &&  '\\' == $result[$length -1])    $result .=  ' ';

        return  $result;
    }/*}}}*/

}

final class DOP extends DataOperation{}

